package cn.tedu.day01.jnsdlfaq.student.controller;

import cn.tedu.day01.jnsdlfaq.util.AjaxResult;
import cn.tedu.day01.jnsdlfaq.student.pojo.Student;
import cn.tedu.day01.jnsdlfaq.student.service.StudentService;
import cn.tedu.day01.jnsdlfaq.util.UUIDGenerator;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 学生管理控制层
 */
@RestController
@RequestMapping("/student")
@CrossOrigin(origins = "*", maxAge = 3600)//跨域
public class StudentController {
    @Autowired
    private StudentService studentService;

    @RequestMapping("/selectAll")
    public AjaxResult selectAll() {
        List<Student> lists = studentService.selectAllStudent();
        return AjaxResult.success(lists);
    }

    @RequestMapping("/addStudent")
    public AjaxResult addStudent(Student student) {
        student.setStuId(UUIDGenerator.getUUID());
        int row = studentService.insertStudent(student);
        return AjaxResult.success(row);
    }

    @RequestMapping("/deleteById")
    public AjaxResult deleteById(@Param("id") String id) {
        System.out.println("id====" + id);
        int row = studentService.deleteStuById(id);
        return AjaxResult.success(row);
    }


}
